﻿<%@ Page Language="C#" ValidateRequest="false" %>
<%@ Register Assembly="Typps" Namespace="Typps" TagPrefix="t" %>
<%--/*http://developer.yahoo.com/yui/yuitest/*/--%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <!--CSS-->
    <link rel="stylesheet" type="text/css" href="../yuitest/css/logger.css" />
    <link rel="stylesheet" type="text/css" href="../yuitest/css/testlogger.css" />
    <!-- Dependencies -->
    <script src="../yuitest/yahoo-dom-event.js" type="text/javascript"></script>
    <script src="../yuitest/logger-min.js" type="text/javascript"></script>
    <!-- Source File -->
    <script src="../yuitest/yuitest-min.js" type="text/javascript"></script>
    <script src="../yuitest/event-simulate-min.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" ScriptMode="Debug" runat="server">
        </asp:ScriptManager>
        <t:Editor ID="Editor1" runat="server"></t:Editor>
        <br style="clear:both"/>
        <div id="tabs_test"></div>
    </div>
    <script type="text/javascript">
    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoadedHandler)
    function pageLoadedHandler(sender, eventArgs) {
        var oTestCase = new YAHOO.tool.TestCase({

            name: "Tabs",

            //---------------------------------------------
            // Setup and tear down
            //---------------------------------------------

            setUp: function () {
                this.editor = $find('<%= Editor1.ClientID %>');
            },

            tearDown: function () {
                delete this.editor;
            },

            //---------------------------------------------
            // Tests
            //---------------------------------------------
            testTabBarCollection: function () {
                var length = this.editor.get_tabCollection().length;
                YAHOO.util.Assert.areEqual(5, length, "length should be 5");
            },

            testTabs: function () {
                var items = this.editor.get_tabs().items;
                var length = 0;
                for (var index in items)
                    length++;
                YAHOO.util.Assert.areEqual(5, length, "length should be 5");
            },

            testTabsDecendantsContractVerification: function () {
                var isToolBarItemType = false;
                var tabs = this.editor.get_tabs();
                var implementsIComposite = Typps.IComposite.isImplementedBy(tabs);
                YAHOO.util.Assert.areEqual(implementsIComposite, true, "All tab collections must implement the IComposite contract");
                var implementsBarBase = Typps.BarBase.isInstanceOfType(tabs);
                YAHOO.util.Assert.areEqual(implementsBarBase, true, "The tab collection must implement the BarBase class");
                var tabItems = tabs.items;
                for (var i in tabItems) {
                    var tab = tabItems[i];
                    var implementsBarItemBase = Typps.BarItemBase.isInstanceOfType(tab);
                    YAHOO.util.Assert.areEqual(implementsBarItemBase, true, "Every TabItem must implement the base class BarItemBase");
                    var isTabItemType = Typps.TabItem.isInstanceOfType(tab);
                    YAHOO.util.Assert.areEqual(isTabItemType, true, "Every TabItem must be of type TabItem");
                    var implementsIButtonItem = Typps.IButtonItem.isInstanceOfType(tab);
                    YAHOO.util.Assert.areEqual(implementsIButtonItem, true, "Every TabItem must implement the IButtonItem interface");
                }
            },

            testTabIconsModeAddGetRemove: function () {
                tabItemsTest(this.editor, { mode: 0 });
            },

            testTabImageSpritesModeAddGetRemove: function () {
                tabItemsTest(this.editor, { mode: 1 });
            }
        });
        var tabItemsTest = function (instance, options) {
            var divider = false;
            var enabled = true;
            var icon = null;
            var marginLeft = 0;
            var index = 0;
            var title = 'hello';
            var isOptions = false;
            var leftBorderImage = '';
            var optionsName = '';
            var optionsImage = '';
            var optionsTitle = '';
            var barItemType = 1; /*Typps.BarItemType.TabItem*/
            var distance = 0;
            var width = 0;
            var name1 = '';
            var name2 = '';
            var disabledBackColor = '';
            var disabledBorderColor = '';
            var disabledTransparency = '';
            var selected = false;
            instance.set_mode(options.mode); //Typps.Editor.IconType.ImageSprites == 0
            var tabs = instance.get_tabs();

            var command = new Typps.Command(null/*ToolBarItem will make itself the sender when null*/, function (sender, args) {
                name1 = sender.get_name();
            });
            var tabItem = instance.createTabItem('item1', divider, icon, marginLeft, index, title, isOptions, enabled, barItemType, width, distance, selected,
            disabledBackColor, disabledBorderColor, disabledTransparency, command, document.createElement('a'));
            tabs.add(tabItem);

            var length = 0;
            for (var i in tabs.items)
                length++;
            YAHOO.util.Assert.areEqual(6, length, "length should be exactly 6 because we have 5 initial items and then an extra TabItem was added manually");

            var item1 = tabs.item('item1');
            YAHOO.util.Assert.areEqual(tabItem, item1, "we were not able to retrieve the element we added?");
            YAHOO.util.UserAction.click(item1.get_element());
            YAHOO.util.Assert.areEqual('item1', name1, String.format("the name of this command must be {0}", name1));

            tabs.remove('item1');
            length = 0;
            for (var j in tabs.items)
                length++;

            YAHOO.util.Assert.areEqual(5, length, "length should be 5 since we removed the TabItem we added manually");
            //clean up
            tabItem.dispose();
        }
        //create the logger
        var logger = new YAHOO.tool.TestLogger();

        //add the test cases and suites
        YAHOO.tool.TestRunner.add(oTestCase);

        //run all tests
        YAHOO.tool.TestRunner.run();
    }
    </script>
    </form>
</body>
</html>
